package com.luoyi.util.mpaas;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * @author tail7
 */
public class DictJsonToExcelReplace {

    /**
     * 字典json转成excel导出的replace
     * @param args
     */
    public static void main(String[] args) {
        String aa = "[\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"value\": \"1\",\n" +
                "\t\t\t\t\"text\": \"用户下单\",\n" +
                "\t\t\t\t\"categoryId\": \"1808794632368955394\",\n" +
                "\t\t\t\t\"isDefault\": false\n" +
                "\t\t\t},\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"value\": \"2\",\n" +
                "\t\t\t\t\"text\": \"推荐下单\",\n" +
                "\t\t\t\t\"categoryId\": \"1808794632368955394\",\n" +
                "\t\t\t\t\"isDefault\": false\n" +
                "\t\t\t},\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"value\": \"3\",\n" +
                "\t\t\t\t\"text\": \"客户下单\",\n" +
                "\t\t\t\t\"categoryId\": \"1808794632368955394\",\n" +
                "\t\t\t\t\"isDefault\": true\n" +
                "\t\t\t}\n" +
                "\t\t]";

        JSONArray objects = JSONObject.parseArray(aa);
        String start = "{";
        for (Object object : objects) {
            JSONObject jsonObject = (JSONObject) object;
            String value = StrUtil.format("\"{}_{}\"", jsonObject.get("text"), jsonObject.get("value"));
            start += value + ",";
        }
        start = StrUtil.removeSuffix(start, ",");
        start += "}";
        System.out.println(start);


    }
}
